<template>
  <div>
    <div style="display: flex; justify-content: flex-end">
      <el-button
        @click="$router.push('new')"
        size="small"
        style="width: 97px"
        type="success"
        icon="el-icon-edit"
        >新增试题</el-button
      >
    </div>
    <el-form
      style="display: flex; flex-wrap: wrap; margin-top: 13px; height: 153px"
    >
      <el-form-item label="学科" label-width="80px" style="width: 25%">
        <el-select
        @change="subjectsChange"
          v-model="form.subjects"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in subjects"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级目录" label-width="80px" style="width: 25%">
        <el-select
          v-model="form.catalog"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in catalog"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="标签" label-width="80px" style="width: 25%">
        <el-select
          v-model="form.tags"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in tags"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="关键字" label-width="80px" style="width: 25%">
        <el-input
          v-model="form.keyword"
          placeholder="根据题干搜索"
          size="small"
          style="width: 100%"
        ></el-input>
      </el-form-item>
      <el-form-item label="试题类型" label-width="80px" style="width: 25%">
        <el-select
          v-model="form.questionType"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in questionType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="难度" label-width="80px" style="width: 25%">
        <el-select
          v-model="form.difficulty"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in difficulty"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="方向" label-width="80px" style="width: 25%">
        <el-select
          v-model="form.direction"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in direction"
            :key="item.value"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="录入人" label-width="80px" style="width: 25%">
        <el-select
          v-model="form.creatorID"
          placeholder="请选择"
          size="small"
          style="width: 100%"
        >
          <el-option
            v-for="item in creatorID"
            :key="item.value"
            :label="item.username"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="题目备注" label-width="80px" style="width: 25%">
        <el-input v-model="form.remarks" size="small" style="width: 100%"></el-input>
      </el-form-item>
      <el-form-item label="企业简称" label-width="80px" style="width: 25%">
        <el-input v-model="form.shortName" size="small" style="width: 100%"></el-input>
      </el-form-item>
      <el-form-item label="城市" label-width="80px" style="width: 25%">
        <el-select
        @change="provincesChange"
          v-model="form.provinces"
          placeholder="请选择"
          size="small"
          style="width: 49%; margin-right: 2%;"
        >
          <el-option
            v-for="item in provinces"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
        <el-select
          v-model="form.citys"
          placeholder="请选择"
          size="small"
          style="width: 49%"
        >
          <el-option
            v-for="item in citys"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item style="margin-left: auto">
        <el-button size="small" @click="clear">清除</el-button>
        <el-button size="small" type="primary" @click="search(form)">搜索</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { simple } from '@/api/hmmm/subjects'
import { simples } from '@/api/hmmm/tags'
import { simpledirectorys } from '@/api/hmmm/directorys'
import { direction } from '@/api/hmmm/constants'
import { userSimple } from '@/api/base/users'
import { provinces, citys } from '@/api/hmmm/citys'
export default {
  name: 'forms',
  props: ['search'],
  data () {
    return {
      citys: [],
      provinces: [],
      subjects: {},
      catalog: {},
      tags: {},
      form: {},
      forms: {},
      direction: [],
      questionType: [{
        value: 1,
        label: '单选'
      }, {
        value: 2,
        label: '多选'
      }, {
        value: 3,
        label: '简答'
      }],
      difficulty: [{
        value: 1,
        label: '简单'
      }, {
        value: 2,
        label: '一般'
      }, {
        value: 3,
        label: '困难'
      }],
      creatorID: []
    }
  },
  async created () {
    const { data: res } = await simple()
    this.subjects = res
    this.direction = direction
    const { data: res2 } = await userSimple()
    this.creatorID = res2
    this.provinces = provinces()
  },
  methods: {
    async subjectsChange (val) {
      this.forms.subjectID = val
      const { data: res } = await simples(this.forms)
      this.tags = res
      const { data: res1 } = await simpledirectorys(this.forms)
      this.catalog = res1
    },
    async provincesChange (val) {
      const res = await citys(val)
      this.citys = res
    },
    clear () {
      this.form = {}
      this.catalog = {}
      this.citys = []
      this.tags = {}
    }
  }
}
</script>

<style scoped lang='scss'>
.el-form-item {
  margin-bottom: 0px;
}
</style>
